<?php
class teacherAction extends apiAction
{
	public $_mod = '';
	public $cache = '';
	public $cache_name = '';
    public function _initialize() {
		parent::_initialize();
		$this->_mod = D('daka_user');
    }
    
	public function index() {
		$page = $this->_get('page','intval',1);//默认第一页
        $pagenum = $this->_get('pagenum','intval',10);//默认10条数据
		$time = $this->_get('time','intval',strtotime(date('Y-m-d',time()-60*24*3600)));//默认前60天 当天整点时间戳 开始的数据
		$map['time'] = array('gt',$time);//查询条件 大于time
		$map['status'] = 1;//查询条件 是开启
		
		$page = ($page - 1) * $pagenum;//分页处理
		$field = 'id,uname as name,ico as img,photo,type,type_remark as remark,content,ordid';
		$order = 'ordid asc,time desc';//分段排序
		$list = $this->_mod->field($field)->where($map)->order($order)->limit($page,$pagenum)->select();
		$json = array();
		$tmp = array();
		if($list){
			foreach($list as $k => $v){
				$list[$k]['url'] = U('home/teacher/detail',array('id'=>$v['id']));
			}
		}
        $data['msg'] = count($list)?'获取成功':'没有数据';
		$data['status'] = count($list)?1:0;
		$data['data'] = $list;
		$this->APIreturn($data);
    }
	public function detail() {
		$map['id'] = $this->_get('id','intval',0);
		$map['status'] = 1;//查询条件 是开启
		$field = 'id,uname as name,ico,img,photo,type,type_remark as remark,content,resume';
		$list = $this->_mod->field($field)->where($map)->find();
		
        $data['msg'] = $list?'获取成功':'没有讲师数据';
		$data['status'] = $list?1:0;
		$data['data'] = $list;
		$this->APIreturn($data);
    }
	
	public function paper() {
		$page = $this->_get('page','intval',1);//默认第一页
        $pagenum = $this->_get('pagenum','intval',10);//默认10条数据
		$time = $this->_get('time','intval',strtotime(date('Y-m-d',time()-60*24*3600)));//默认前60天 当天整点时间戳 开始的数据
		$map['time'] = array('gt',$time);//查询条件 大于time
		$map['uid'] = $this->_get('id','intval',0);
		$map['status'] = 1;//查询条件 是开启
		$page = ($page - 1) * $pagenum;//分页处理
		$order = 'ordid asc,time desc';//分段排序
		$field = 'id,title,img,url,share_num,read_num,is_hot';
	
		$list = D('daka_paper')->field($field)->where($map)->order($order)->limit($page,$pagenum)->select();
		
		
        $data['msg'] = count($list)?'获取成功':'没有数据';
		$data['status'] = count($list)?1:0;
		$data['data'] = $list;
		$this->APIreturn($data);
    }
	public function contribute()
    {
        $page = $this->_get('page','intval',1);
        $pagenum = $this->_get('pagenum','intval',10);
		$time = $this->_get('time','intval',strtotime(date('Y-m-d',time()-60*24*3600)));//默认前60天 当天整点时间戳 开始的数据
		
		$map['u.status'] = 1;//查询条件 开启的用户
		$map['p.status'] = 1;//查询条件 开启的文章
		$map['u.time'] = array('gt',$time);//查询条件 大于time
		$map['p.time'] = array('gt',$time);//查询条件 大于time
		
		$page = ($page - 1) * $pagenum;//分页处理
		$order = 'num desc,u.time desc';//分享数高排序  时间倒序
		$field = 'u.uname,u.photo,count(1) AS num';
		$U = D('daka_user');
		$P = D('daka_paper');
		$list = $P->table($P->getTableName().' p')->field($field)->join($U->getTableName().' u on u.id=p.uid')->where($map)->group('p.uid')->order($order)->limit($page,$pagenum)->select();
		
		
		$data['msg'] = count($list)?'获取成功':'没有数据';
		$data['status'] = count($list)?1:0;
		$data['data'] = $list;
		$this->APIreturn($data);
    }
	
	public function student(){
        $page = $this->_get('page','intval',1);
        $pagenum = $this->_get('pagenum','intval',10);
		$time = $this->_get('time','intval',strtotime(date('Y-m-d',time()-60*24*3600)));//默认前60天 当天整点时间戳 开始的数据
		$page = ($page - 1) * $pagenum;
		$map['time'] = array('gt',$time);//查询条件 大于time
		$order = 'read_num desc,time desc';//阅读数高排序 时间倒序
		$field = 'name,photo,read_num';
		$list = D('student')->field($field)->where($map)->order($order)->limit($page,$pagenum)->select();
		
		$data['msg'] = count($list)?'获取成功':'没有数据';
		$data['status'] = count($list)?1:0;
		$data['data'] = $list;
		$this->APIreturn($data);
	}
	

}